package me.algo.n;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author guozheng
 * @date 2024/8/2
 */
public class N3 {
    static public int[] twoSum(int[] nums, int target) {
        if (nums == null || nums.length == 0) {
            return new int[0];
        }
        if (nums.length == 1) {
            return new int[0];
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            int i1 = target - num;
            boolean b = map.containsKey(i1);
            if (b) {
                Integer idx = map.get(i1);
                if(idx == i) {
                    continue;
                }
                return new int[]{i, idx};
            }
        }
        return new int[0];
    }


    public static void main(String[] args) {

    }

}
